package com.lphl.pet.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import com.lphl.pet.base.BasePager;

public class MyPagerAdapter extends PagerAdapter {

	private Context ctx;
	private ArrayList<BasePager> pagers;

	public MyPagerAdapter(Context ctx, ArrayList<BasePager> pagers) {
		this.ctx = ctx;
		this.pagers = pagers;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		((ViewPager) container).addView(pagers.get(position).getRootView());
		return pagers.get(position).getRootView();
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		((ViewPager) container).removeView((View)object);
	}

	@Override
	public int getCount() {
		return pagers.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}
}